<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>活动详情修改</title>
    <link href="$!webPath/css/template.css"  rel="stylesheet" type="text/css">
    <link href="$!webPath/css/jquery-ui-1.8.22.custom.css" type=text/css rel=stylesheet>
    <script src="$!webPath/js/jquery.min.js"></script>
    <script src="$!webPath/js/jquery-1.6.2.js"></script>
    <script src="$!webPath/js/jquery-ui-1.8.21.js"></script>
    <script src="$!webPath/js/jquery.form1.js"></script>

</head>
<body>
<div class="header_nav">
    <iframe name="content_frame" src="$!webPath/admin/nav" marginwidth=0 marginheight=0  frameborder=0 width=100% height=80/></iframe>
    <div class="cont_right"><a href="$!webPath/login">注销</a></div>
</div>
<div class="cont">
    <h3 class="seth">编辑</h3>
    <div class="nav_list">
        <ul id="ul_table">
            <li><a href="$!webPath/admin/listAllActivity?size=10&page=0&type=0"><b>活动列表</b></a></li>
            <li><a href="$!webPath/admin/activityContent" class="this"><b>内容编辑</b></a></li>
        </ul>
    </div>
    #if($!activityContentEntities.size()<=0)
    <form method="post" name="theForm" id="theForm"  enctype="multipart/form-data">
        请选择要添加的类型：
        <select id="add_type">
            <option selected>--请选择--</option>
            <option value="0">文章</option>
            <option value="1">图片</option>
            <option value="2">视频</option>
        </select>
        <div id="div_text" style="display: none;">
            文章内容：<textarea class="text_edit" name="text" id="text_edit" cols="100" rows="8">null</textarea><br/>
        </div>
        <div id="div_img" style="display: none;">
            图片：<input type="file" id="img_edit" name="photo" style="opacity:1;position: static;" accept="image/jpg,image/jpeg,image/png"><br/>
            <input type="hidden" name="picPath" id="picPath" value="null">
        </div>
        <div id="div_video" style="display: none;">
            视频路径：<input id="video_edit" type="text" name="videoPath" value="null"/>
        </div>
        序列号：<input name="sequence" id="squ" value="" type="text">
        <input type="hidden" id="activityId" value="" name="activityId"/>
        <input name="save" type="button" value="提交" onclick="btnSave1()">
    </form>
    #else
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="fshop_table">
            <div >
                #foreach($obj in $!activityContentEntities)
                <form method="post" name="theForm" id="theForm$!obj.id"  enctype="multipart/form-data">
                <tr id="del$!obj.id">
                    <td>显示
                        <br/>
                        #if(""!=$!obj.activityText && $!obj.activityText)
                        <div style="width: 100%;">
                            #set($activityText=$!utilsTools.transformStringNewLine("$!obj.activityText"))
                                <textarea class="text_edit" name="text" id="text$!obj.id" cols="100" rows="8">$!activityText</textarea>
                        </div>
                        #elseif(""!=$!obj.activityPicPath && $!obj.activityPicPath)
                        <div>
                        <img class="detail_img" src="$!webPath/$!obj.activityPicPath" width="100%" height="400px"/>
                        修改图片：<input type="file" id="$!obj.id" name="photo" style="opacity:1;position: static;" accept="image/jpg,image/jpeg,image/png">
                        <input type="hidden" name="picPath" id="picPath$!obj.id" value="null">
                        </div>
                        #elseif(""!=$!obj.activityVideoPath && $!obj.activityVideoPath )
                        <div>
                        <video width="320" height="240" controls autoplay>
                            <source src="$!obj.activityVideoPath" type="video/ogg">
                            <source src="$!obj.activityVideoPath" type="video/mp4">
                            <source src="$!obj.activityVideoPath" type="video/webm">
                            <object data="movie.mp4" width="320" height="240">
                                <embed width="320" height="240" src="$!obj.activityVideoPath">
                            </object>
                        </video>
                        修改视频路径<input type="text" name="videoPath" id="video$!obj.id" value="$!obj.activityVideoPath"/>
                        </div>
                        #end
                        序列号：<input type="text" name="sequence" id="sequ$!obj.id" value="$!obj.activitySequence"/>
                        <div class="detail_event">
                            <input type="hidden" id="" name="activityContentId" value="$!obj.id">

                            <input type="hidden" id="activityId$!obj.id" name="activityId" value="">
                            <input name="save" type="button" value="提交" onclick="btnSave('$!obj.id')">
                            <input name="" type="button" value="删除" onclick="btnDel('$!obj.id')">
                            <input name="" type="button" value="添加" onclick="btnAdd()">

                        </div>
                    </td>
                </tr>
                </form>
                #end
                <div id="div_add" style="display:none;">
                    <form method="post" name="theForm" id="theForm1"  enctype="multipart/form-data">
                        请选择要添加的类型：
                        <select id="add_type1">
                            <option selected>--请选择--</option>
                            <option value="0">文章</option>
                            <option value="1">图片</option>
                            <option value="2">视频</option>
                        </select>
                        <div id="div_text1" style="display: none;">
                            文章内容：<textarea class="text_edit" name="text" id="textarea1" cols="100" rows="8" ></textarea><br/>
                        </div>
                        <div id="div_img1" style="display: none;">
                            图片：<input type="file" id="img1" name="photo" style="opacity:1;position: static;" accept="image/jpg,image/jpeg,image/png"><br/>
                            <input type="hidden" name="picPath" id="picPath1" >
                        </div>
                        <div id="div_video1" style="display: none;">
                            视频路径：<input type="text" id="videoPath1" name="videoPath"/>
                        </div>
                        序列号：<input name="sequence" value="" id="squ1" type="text">
                        <input type="hidden" name="activityId" id="activityId1" value="">
                        <input name="save" type="button" value="提交" onclick="btnSave2()">
                    </form>
                </div>
            </div>
            #end
        </table>

</div>
<script>
    $(function(){
        getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]); return null;
        }
        activityId=getUrlParam('activityId');
    })
    $('#add_type').change(function(){
        if($('#add_type option:selected').val()==0){
            $('#div_text').css('display','block');
            $('#div_img').css('display','none');
            $('#div_video').css('display','none');

        }else if($('#add_type option:selected').val()==1){
            $('#div_text').css('display','none');
            $('#div_img').css('display','block');
            $('#div_video').css('display','none');

        }else if($('#add_type option:selected').val()==2){
            $('#div_text').css('display','none');
            $('#div_img').css('display','none');
            $('#div_video').css('display','block');

        }
    })
    function btnSave1(){
        $('#picPath').val(null);
        if($('#add_type option:selected').val()==0){
            if($('#text_edit').val()==''){
                alert('请输入文章内容');
                return false;
            }else{
                var textarea=$('#text_edit').val();
                $('#text_edit').val(((textarea.replace(/<(.+?)>/gi,"&lt;$1&gt;")).replace(/ /gi,"&nbsp;")).replace(/\n/gi,"<br/>"));
                $('#div_img').remove();
                $('#div_video').remove();
            }
        }else if($('#add_type option:selected').val()==1){
            if($('#img_edit').val()==''){
                alert('请选择要上传的图片');
                return false;
            }else{
                $('#div_text').remove();
                $('#div_video').remove();
                $('#picPath').val($('#img_edit').val());
            }
        }else if($('#add_type option:selected').val()==2){
            if($('#video_edit').val()==''){
                alert('请输入视频地址');
                return false;
            }else{
                $('#div_text').remove();
                $('#div_img').remove();
            }
        }

        $('#activityId').val(activityId);
        if($('#squ').val()==''){
            alert('请输入序列号');
            return false;
        }
        $("#theForm").ajaxSubmit({
            url : "$!webPath/admin/activityContentEdit",
            type : "post",
            success : function(data) {
                window.location.href = "$!webPath/admin/activityContent?activityId="+activityId;
            },
            error : function(data) {
                alert('失败');
            }
        });
    }
    function btnSave(id){
        var sequence_id=$('#sequ'+id).attr('id');
        var sequence=$('#'+sequence_id).val();
        var textTitle=$('#text'+id).val();
        var picPath=$('#'+id).val();
        var video_input=$('#video'+id).val();
        $('#activityId'+id).val(activityId);
        if(textTitle!=''&&picPath==undefined&&video_input==undefined){
            $('#text'+id).val(((textTitle.replace(/<(.+?)>/gi,"&lt;$1&gt;")).replace(/ /gi,"&nbsp;")).replace(/\n/gi,"<br/>"));
            //$('#picPath'+id).val(null);
            //$('#video'+id).val(null);
        }else if(textTitle==undefined&&picPath!=''&&video_input==undefined){
            $('#picPath'+id).val(picPath);
            $('#text'+id).val(null);
            $('#video'+id).val(null);
            console.log(picPath+'--'+$('#picPath'+id).val());
        }else if(textTitle==undefined&&picPath==undefined&&video_input!=''){
            $('#picPath'+id).val(null);
            $('#text'+id).val(null);
        }else{
            alert('请填写你要修改的项');
            return false;
        }
        $("#theForm"+id).ajaxSubmit({
            url : "$!webPath/admin/activityContentEdit",
            type : "post",
            success : function(data) {
                window.location.href = "$!webPath/admin/activityContent?activityId="+activityId;
            },
            error : function(data) {
                alert('失败');
            }
        });
    }
    function btnDel(id){
        if(confirm("你确定要删除吗？")){
            $.ajax({
                url:'$!webPath/admin/deleteActivityContent?contentId='+id,
                type:'delete',
                success: function () {
                    $('#del'+id).remove();
                },
                error:function(){
                    alert('删除失败');
                }
            })
        }
    }
    function btnAdd(){
        $('#div_add').css('display','block');
        $('#add_type1').change(function(){
            if($('#add_type1 option:selected').val()==0){
                $('#div_text1').css('display','block');
                $('#div_img1').css('display','none');
                $('#div_video1').css('display','none');
            }else if($('#add_type1 option:selected').val()==1){
                $('#div_text1').css('display','none');
                $('#div_img1').css('display','block');
                $('#div_video1').css('display','none');
            }else if($('#add_type1 option:selected').val()==2){
                $('#div_text1').css('display','none');
                $('#div_img1').css('display','none');
                $('#div_video1').css('display','block');
            }
        })
    }
    function btnSave2(){
        $('#picPath').val(null);
        if($('#add_type1 option:selected').val()==0){
            if($('#texteare1').val()==''){
                alert('请输入文章内容');
                return false;
            }else{
                var textarea=$('#texteare1').val();
                $('#texteare1').val(((textarea.replace(/<(.+?)>/gi,"&lt;$1&gt;")).replace(/ /gi,"&nbsp;")).replace(/\n/gi,"<br/>"));
                $('#div_video1').remove();
                $('#div_img1').remove();
            }
        }else if($('#add_type1 option:selected').val()==1){
            if($('#img1').val()==''){
                alert('请选择要上传的图片');
                return false;
            }else{
                $('#picPath1').val($('#img1').val());
                $('#div_text1').remove();
                $('#div_video1').remove();
            }
        }else if($('#add_type1 option:selected').val()==2){
            if($('#videoPath1').val()==''){
                alert('请输入视频地址');
                return false;
            }else{
                $('#div_text1').remove();
                $('#div_img1').remove();
            }
        }

        $('#activityId1').val(activityId);
        if($('#squ1').val()==''){
            alert('请输入序列号');
            return false;
        }
        $("#theForm1").ajaxSubmit({
            url : "$!webPath/admin/activityContentEdit",
            type : "post",
            success : function(data) {
                $('#div_add').css('display','none');
                window.location.href = "$!webPath/admin/activityContent?activityId="+activityId;
            },
            error : function(data) {
                alert('失败');
            }
        });
    }
</script>
</body>
</html>